<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>12用户更新</title>
  <style>
    * {
      padding: 0;
      margin: 0;
      list-style: none;
    }

    #table {
      border: 1px solid #000000;
      width: 600px;
      margin: 20px auto 0;
    }

    .head {
      display: flex;
      background: #e1e1e1;
      height: 30px;
      line-height: 30px;
    }

    .head li {
      flex: 1;
      text-align: center;
    }

    #body li {
      display: flex;
    }

    #body li span {
      flex: 1;
      text-align: center;
      height: 30px;
      line-height: 30px;
    }
  </style>
</head>

<body>
  <p><label>用户名：<input type="text" disabled placeholder="请输入用户名" id="username"></label></p>
  <p><label>密码：<input type="text" placeholder="请输入密码" id="password"></label></p>
  <p><label>手机号：<input type="text" placeholder="请输入手机号" id="telephone"></label></p>
  <p><button id="update">提交</button></p>
</body>
<script src="./util.js"></script>
<script src="./ajax.js"></script>
<script>
  var oUserName = document.querySelector('#username');
  var oPassword = document.querySelector('#password');
  var oTelephone = document.querySelector('#telephone');
  var oUpdate = document.querySelector('#update');


  var id = queryString('id');

  // alert(id);


  ajax({
    path: 'http://localhost/1907/25user_info.php',
    data: {
      id
    },
    successCB: data => {
      console.log(data);
      // {
      //   code: 1
      // }
      if (data.code == 1) {

        var { username, password, telephone } = data.data;
        oUserName.value = username;
        oPassword.value = password;
        oTelephone.value = telephone;



      } else {
        alert(data.msg);
      }
    }
  })

  oUpdate.onclick = function () {
    // username = oUserName.value;
    var password = oPassword.value;
    var telephone = oTelephone.value;

    // 前端验证

    ajax({
      path: 'http://localhost/1907/26user_update.php',
      data: {
        password,
        telephone,
        id
      },
      successCB: data => {
        if (data.code == 1) {
          location.href = './08用户列表.html';
        } else {
          alert(data.msg);
        }
      }
    })

  }





</script>

</html>